home *** CD-ROM | disk | FTP | other *** search
- Path: anvil.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: line intersection in C
- Date: 27 Feb 1996 12:18:28 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4gvoukINNbdl@anvil.ugrad.cs.ubc.ca>
- References: <1996Feb25.230142.29689@dcs.warwick.ac.uk>
- NNTP-Posting-Host: anvil.ugrad.cs.ubc.ca
-
- In article <1996Feb25.230142.29689@dcs.warwick.ac.uk>,
- Daniel Castillo Molero <D.C.Molero@dcs.warwick.ac.uk> wrote:
- >
- >Hello,
- >
- >I wonder if anybody can help me to find an algorithm in C to detect whether
- >two line segments intersect properly (I don't know if this is the correct
- >terminology, but by proper intersection I mean that the intersection is
- >not in the extreme of any of them and that one does not lie on top of
- >the other).
-
- Ask on comp.graphics.algorithms. Read FAQ first. This is a fairly
- straightforward linear algebra problem.
-
- >I need to test intersection just for line segments whose slope is a multiple
- >of 45 degrees, which I suppose may simplify the solution.
-
- This admits lines that have infinite slope, so you have to use an implicit
- representation of a line:
-
- Ax + By - C = 0.
-
- This way you never have to deal with problems like infinite slopes. Any line
- can be represented with finite A, B, and C.
-
- The two lines intersect if the dot product of (A1, B1) and (-B2, A2) is not
- zero. (A1, B1) is a vector perpendicular to one line, (-B2, A2) is a vector in
- the direction of one line. If the dot product is zero, they are at 90 degrees
- and hence the lines are parallel. Otherwise, they intersect.
-
- The fact that they are multiples of 45 degrees might help you in finding the
- actual intersection point in particular if the lines lie along some fixed
- lattice grid, but you only asked how to check whether they
- intersect or not. :)
- --
-
-